
package com.hex.ds.code.detection.common.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hex.ds.code.detection.common.constants.CommonConstants;
import com.hex.ds.code.detection.common.constants.ScanCommonConstants;
import com.hex.ds.code.detection.common.dao.ClusterSparingConfMapper;
import com.hex.ds.code.detection.common.dto.HotBackupDTO;
import com.hex.ds.code.detection.common.dto.TableSyncDTO;
import com.hex.ds.code.detection.common.entity.ClusterSparingConf;
import com.hex.ds.code.detection.common.service.ClusterSparingConfService;
import java.util.Map;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 集群热备配置表
 *
 * @author yemw
 * @date 2023-08-30 14:09:32
 */
@Service
public class ClusterSparingConfServiceImpl extends ServiceImpl<ClusterSparingConfMapper, ClusterSparingConf> implements
    ClusterSparingConfService {

    @Override
    public Page queryList(Page page, ClusterSparingConf clusterSparingConf) {
        LambdaQueryWrapper<ClusterSparingConf> wrapper = Wrappers.lambdaQuery();
        wrapper.select().eq(ClusterSparingConf::getDel, CommonConstants.STATUS_NORMAL)
                .like(StrUtil.isNotBlank(clusterSparingConf.getClusterName()),ClusterSparingConf::getClusterName,(clusterSparingConf.getClusterName()));
        Page returnPage = this.baseMapper.selectPage(page, wrapper);
        return returnPage;
    }

    @Override
    public List<ClusterSparingConf> queryListNoPage(ClusterSparingConf clusterSparingConf) {
        LambdaQueryWrapper<ClusterSparingConf> wrapper = Wrappers.lambdaQuery();
        wrapper.select().eq(ClusterSparingConf::getDel, CommonConstants.STATUS_NORMAL)
                .like(StrUtil.isNotBlank(clusterSparingConf.getClusterName()),ClusterSparingConf::getClusterName,(clusterSparingConf.getClusterName()));
        return this.baseMapper.selectList(wrapper);
    }

    /**
     * 首页-热备数据总量
     * @param hotBackupDTO
     * @return
     */
    @Override
    public Map<String, Object> hotBackupTotal(HotBackupDTO hotBackupDTO) {
        hotBackupDTO.setStaTime(hotBackupDTO.getStaTime()+" 00:00:00");
        hotBackupDTO.setEndTime(hotBackupDTO.getEndTime()+" 23:59:59");
        hotBackupDTO.setYrb(ScanCommonConstants.ClusterName.YWC.value);
        hotBackupDTO.setDrb(ScanCommonConstants.ClusterName.DDZ.value);
        hotBackupDTO.setRbz(ScanCommonConstants.ClusterName.JXZ.value);
        hotBackupDTO.setSb(ScanCommonConstants.ClusterName.YC.value);
        hotBackupDTO.setMenu(ScanCommonConstants.ClusterName.SJRB.value);
        hotBackupDTO.setMessageSubject(ScanCommonConstants.ClusterName.YSJHQ.value);
        return this.baseMapper.hotBackupTotal(hotBackupDTO);
    }

    /**
     * 首页-表同步方式情况
     * @return
     */
    @Override
    public Map<String, Object> TableSyncTotal(TableSyncDTO tableSyncDTO) {
        tableSyncDTO.setDqr(ScanCommonConstants.ClusterName.DQR.value);
        tableSyncDTO.setYqr(ScanCommonConstants.ClusterName.YQR.value);
        tableSyncDTO.setYgl(ScanCommonConstants.ClusterName.YGL.value);
        return this.baseMapper.TableSyncTotal(tableSyncDTO);
    }

}
